package tmproject.hlhj.fhp.tmvote.presenters

import android.content.Context
import com.example.mymvp.BasePresenter
import tmproject.hlhj.fhp.tmvote.beans.*
import tmproject.hlhj.fhp.tmvote.module.VotingModule
import tmproject.hlhj.fhp.tmvote.views.VotingView

/**
 * Created by Never Fear   on 2018\8\6 0006.
Never More....
 */
class VotingPresenter : BasePresenter<VotingModule, VotingView>(), VotingModule.OnVotingResp {
    private var votePosition=0;
    override fun createModule() {
        module= VotingModule()
        module.listener=this
    }
    //获取详情数据
    fun getVotingData(id:Int,appStr:String,context: Context){
        module.getVotingData(id,appStr,context)
    }

    //获取选手数据
    fun getPlayers(id:Int,page:Int,pageSize:Int,context: Context){
        module.getPlayerList(id,page,pageSize,context)
    }
    //投票
    fun vote(competitor_id:String,user_id:String,context: Context,votePostion:Int){
        votePosition=votePostion
        module.vote(competitor_id, user_id, context)
    }
    /*搜索*/
    fun search(activity_id:String,name:String,context: Context){
        module.search(activity_id,name,context)
    }
    /*获取分享*/
    fun getShare(activity_id: Int,context: Context){
        module.getShareUrl(activity_id,context)
    }
    override fun onVotingResp(votingBean: VotingBean) {
        view?.gotVotingData(votingBean)
    }

    override fun onPlayerListBean(playerListBean: PlayerListBean) {
        view?.setPlayerList(playerListBean)
    }

    override fun onVoteResp(baseBean: BaseBean) {
        view?.getVoteResult(baseBean,votePosition)
    }

    override fun onSearchResp(searchBean: SearchBean) {
        view?.gotSearchResult(searchBean)
    }

    override fun onShareUrlResp(baseBean: ShareBean) {
        view?.setShareUrl(baseBean)
    }
}